﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CooStationsToolsNew
{
    /// <summary>
    /// ObjectTreeViewUC.xaml 的交互逻辑
    /// </summary>
    public partial class ObjectTreeViewUC : UserControl
    {
        public static TreeView theTreeView = null;
        public  string theType = null;
        public string theName = null;
        public  UIElement uie = null;
       // List<string> taglist = new List<string>();
        public ObjectTreeViewUC(string objtype,string strname)
        {
            InitializeComponent();
           // List<string> taglist = new List<string>();
            //taglist.Add("true");
           // taglist.Add("true");
            theType = objtype;
            theName = strname;
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            string theUrl = null;
            if(theType=="img")
            {
                theUrl = "pic/o2.png";
            }
            else if (theType == "rect")
            {
                theUrl = "pic/o4.png";
            }
            else if (theType == "div")
            {
                theUrl = "pic/o1.png";
            }
            else if (theType == "txt")
            {
                theUrl = "pic/o3.png";
            }
            else if (theType == "page")
            {
                theUrl = "pic/o5.png";
            }
            img.Source = new BitmapImage(new Uri(theUrl, UriKind.RelativeOrAbsolute));
          //  txtb.Text = theName;
        }

        private void uc_MouseEnter(object sender, MouseEventArgs e)
        {
            uc.BorderBrush = new SolidColorBrush(Color.FromRgb(20,226,226));
            WorkLeftAreaUC.theOtv = sender as ObjectTreeViewUC;
        }

        
        //public void upDataName(string name)
        //{
        //    txtb.Text = name;
        //}
        private void uc_MouseLeave(object sender, MouseEventArgs e)
        {
            uc.BorderBrush = null;
        }
      
        #region 解锁控件集合方法
        //解锁工作区的控件事件
        private void unlockbtn_Click(object sender, RoutedEventArgs e)
        {
            if (uie != null)
            {
                if (theType == "img")
                {
                    Image img = uie as Image;
                    List<string> taglist = img.Tag as List<string>;
                    taglist[0] = "false";
                    img.Tag = taglist;
                    WorkMainAreaUC.layer = AdornerLayer.GetAdornerLayer(WorkMainAreaUC.workcanvas);
                    if (WorkMainAreaUC.myCan != null)
                    {
                        WorkMainAreaUC.layer.Remove(WorkMainAreaUC.myCan);
                    } unlockbtn.Visibility = Visibility.Collapsed;
                    lockbtn.Visibility = Visibility.Visible;
                }
                else if (theType == "rect")
                {
                    Rectangle rect = uie as Rectangle;
                    List<string> taglist = rect.Tag as List<string>;
                    taglist[0] = "false";
                    rect.Tag = taglist;
                    WorkMainAreaUC.layer = AdornerLayer.GetAdornerLayer(WorkMainAreaUC.workcanvas);
                    if (WorkMainAreaUC.myCan != null)
                    {
                        WorkMainAreaUC.layer.Remove(WorkMainAreaUC.myCan);
                    } unlockbtn.Visibility = Visibility.Collapsed;
                    lockbtn.Visibility = Visibility.Visible;
                }
                else if (theType == "div")
                {
                  
                    Canvas can = uie as Canvas;
                    Image img = can.Tag as Image;
                    List<string> taglist = img.Tag as List<string>;
                    taglist[0] = "false";
                    img.Tag = taglist;
                    unlockDivChild((TreeViewItem)this.Parent);
                    for (int i = 0; i < can.Children.Count; i++)
                    {
                        if (can.Children[i].GetType() == typeof(Image))
                        {
                            Image obc = can.Children[i] as Image;
                            List<string> obctaglist = obc.Tag as List<string>;
                            obctaglist[0] = "false";
                            obc.Tag = obctaglist;
                        }
                        if (can.Children[i].GetType() == typeof(Rectangle))
                        {
                            Rectangle obc = can.Children[i] as Rectangle;
                            List<string> obctaglist = obc.Tag as List<string>;
                            obctaglist[0] = "false";
                            obc.Tag = obctaglist;
                        }
                        if (can.Children[i].GetType() == typeof(TextBlock))
                        {
                            TextBlock obc = can.Children[i] as TextBlock;
                            List<string> obctaglist = obc.Tag as List<string>;
                            obctaglist[0] = "false";
                            obc.Tag = obctaglist;
                        }
                        if (can.Children[i].GetType() == typeof(Canvas))
                        {
                            Canvas obc = can.Children[i] as Canvas;
                            Image obc_img = obc.Tag as Image;
                            List<string> obctaglist = obc_img.Tag as List<string>;
                            obctaglist[0] = "false";
                            obc_img.Tag = obctaglist;
                        }
                    }
                    WorkMainAreaUC.layer = AdornerLayer.GetAdornerLayer(WorkMainAreaUC.workcanvas);
                    if (WorkMainAreaUC.myCan != null)
                    {
                        WorkMainAreaUC.layer.Remove(WorkMainAreaUC.myCan);
                    }
                    unlockbtn.Visibility = Visibility.Collapsed;
                    lockbtn.Visibility = Visibility.Visible;
                }
                else if (theType == "page")
                {

                    Canvas can = WorkMainAreaUC.workcanvas;
                    //Image img = can.Tag as Image;
                    //img.Tag = "false";
                    unlockDivChild();
                    for (int i = 0; i < can.Children.Count; i++)
                    {
                        if (can.Children[i].GetType() == typeof(Image))
                        {
                            Image obc = can.Children[i] as Image;
                            List<string> obctaglist = obc.Tag as List<string>;
                            obctaglist[0] = "false";
                            obc.Tag = obctaglist;
                        }
                        if (can.Children[i].GetType() == typeof(Rectangle))
                        {
                            Rectangle obc = can.Children[i] as Rectangle;
                            List<string> obctaglist = obc.Tag as List<string>;
                            obctaglist[0] = "false";
                            obc.Tag = obctaglist;
                        }
                        if (can.Children[i].GetType() == typeof(TextBlock))
                        {
                            TextBlock obc = can.Children[i] as TextBlock;
                            List<string> obctaglist = obc.Tag as List<string>;
                            obctaglist[0] = "false";
                            obc.Tag = obctaglist;
                        }
                        if (can.Children[i].GetType() == typeof(Canvas))
                        {
                            Canvas obc = can.Children[i] as Canvas;
                            Image obc_img = obc.Tag as Image;
                            List<string> obctaglist = obc_img.Tag as List<string>;
                            obctaglist[0] = "false";
                            obc_img.Tag = obctaglist;
                        }
                    }
                    unlockbtn.Visibility = Visibility.Collapsed;
                    lockbtn.Visibility = Visibility.Visible;
                }
            }
        }    
        public void unlockDivChild()
        {
            TreeViewItem tv = theTreeView.Items[0] as TreeViewItem;
            for (int i = 0; i < tv.Items.Count; i++)
            {
                TreeViewItem tvi = tv.Items[i] as TreeViewItem;
                ObjectTreeViewUC ob = tvi.Header as ObjectTreeViewUC;
                if (ob.theType == "div")
                {
                    unlockDivChild(tvi);
                    ob.UnLock();
                }
                else
                {
                    ob.UnLock();
                }
            }
        }
        public void unlockDivChild(TreeViewItem tvi)
        {
            for (int i = 0; i < tvi.Items.Count; i++)
            {
                TreeViewItem tv = tvi.Items[i] as TreeViewItem;
                ObjectTreeViewUC ob = tv.Header as ObjectTreeViewUC;
                if (ob.theType == "div")
                {
                    unlockDivChild(tv);
                    ob.UnLock();
                }
                else
                {
                    ob.UnLock();
                }
            }
        } 
        public void UnLock()
        {
            unlockbtn.Visibility = Visibility.Collapsed;
            lockbtn.Visibility = Visibility.Visible;
        }
        #endregion
        
        #region 锁定控件集合方法
        //锁定工作区的控件事件
        private void lockbtn_Click(object sender, RoutedEventArgs e)
        {
            if (uie != null)
            {
                if (theType == "img")
                {
                    Image img = uie as Image;
                    
                   List<string> taglist = img.Tag as List<string>;
                    taglist[0] = "true";
                    img.Tag = taglist;
                    //ModelTools.layer = AdornerLayer.GetAdornerLayer(MainWindow.canvas);
                    //if (ModelTools.myCan != null)
                    //{
                    //    ModelTools.layer.Remove(ModelTools.myCan);
                    //}
                    lockbtn.Visibility = Visibility.Collapsed;
                    unlockbtn.Visibility = Visibility.Visible;
                }
                else if (theType == "rect")
                {
                    Rectangle rect = uie as Rectangle;
                    List<string> taglist = rect.Tag as List<string>;
                    taglist[0] = "true";
                    rect.Tag = taglist;
                    lockbtn.Visibility = Visibility.Collapsed;
                    unlockbtn.Visibility = Visibility.Visible;
                }
                else if (theType == "div")
                {
                    Canvas can = uie as Canvas;
                    Image img = can.Tag as Image;
                    List<string> taglist = img.Tag as List<string>;
                    taglist[0] = "true";
                    img.Tag = taglist;
                    // Image img = can.Tag as Image;
                    // img.Tag = "true";
                    lockDivChild((TreeViewItem)this.Parent);
                    for (int i = 0; i < can.Children.Count; i++)
                    {
                        if (can.Children[i].GetType() == typeof(Image))
                        {
                            Image obc = can.Children[i] as Image;
                            List<string> obctaglist = obc.Tag as List<string>;
                            obctaglist[0] = "true";
                            obc.Tag = obctaglist;
                        }
                        if (can.Children[i].GetType() == typeof(Rectangle))
                        {
                            Rectangle obc = can.Children[i] as Rectangle;
                            List<string> obctaglist = obc.Tag as List<string>;
                            obctaglist[0] = "true";
                            obc.Tag = obctaglist;
                        }
                        if (can.Children[i].GetType() == typeof(TextBlock))
                        {
                            TextBlock obc = can.Children[i] as TextBlock;
                            List<string> obctaglist = obc.Tag as List<string>;
                            obctaglist[0] = "true";
                            obc.Tag = obctaglist;
                        }
                        if (can.Children[i].GetType() == typeof(Canvas))
                        {
                            Canvas obc = can.Children[i] as Canvas;
                            Image obc_img = obc.Tag as Image;
                            List<string> obctaglist = obc_img.Tag as List<string>;
                            obctaglist[0] = "true";
                            obc_img.Tag = obctaglist;
                        }
                    }

                    lockbtn.Visibility = Visibility.Collapsed;
                    unlockbtn.Visibility = Visibility.Visible;
                }
                else if (theType == "page")
                {
                    lockDivChild();
                    Canvas can = WorkMainAreaUC.workcanvas;

                    for (int i = 0; i < can.Children.Count; i++)
                    {
                        if (can.Children[i].GetType() == typeof(Image))
                        {
                            Image obc = can.Children[i] as Image;
                            List<string> obctaglist = obc.Tag as List<string>;
                            obctaglist[0] = "true";
                            obc.Tag = obctaglist;
                        }
                        if (can.Children[i].GetType() == typeof(Rectangle))
                        {
                            Rectangle obc = can.Children[i] as Rectangle;
                            List<string> obctaglist = obc.Tag as List<string>;
                            obctaglist[0] = "true";
                            obc.Tag = obctaglist;
                        }
                        if (can.Children[i].GetType() == typeof(TextBlock))
                        {
                            TextBlock obc = can.Children[i] as TextBlock;
                            List<string> obctaglist = obc.Tag as List<string>;
                            obctaglist[0] = "true";
                            obc.Tag = obctaglist;
                        }
                        if (can.Children[i].GetType() == typeof(Canvas))
                        {
                            Canvas obc = can.Children[i] as Canvas;
                            Image obc_img = obc.Tag as Image;
                            List<string> obctaglist = obc_img.Tag as List<string>;
                            obctaglist[0] = "true";
                            obc_img.Tag = obctaglist;
                        }
                    }
                    lockbtn.Visibility = Visibility.Collapsed;
                    unlockbtn.Visibility = Visibility.Visible;
                }
            }
        }
        public void lockDivChild()
        {
           
            TreeViewItem tv = theTreeView.Items[0] as TreeViewItem;
            for (int i = 0; i < tv.Items.Count; i++)
            {
                TreeViewItem tvi = tv.Items[i] as TreeViewItem;
                ObjectTreeViewUC ob = tvi.Header as ObjectTreeViewUC;
                if (ob.theType=="div")
                {
                    lockDivChild(tvi);
                    ob.Lock();
                }
                else {
                    ob.Lock();
                }
            }
        }
        public void lockDivChild(TreeViewItem tvi)
        {
            for (int i = 0; i < tvi.Items.Count; i++)
            {
                TreeViewItem tv = tvi.Items[i] as TreeViewItem;
                ObjectTreeViewUC ob = tv.Header as ObjectTreeViewUC;
                if (ob.theType == "div")
                {
                    lockDivChild(tv);
                    ob.Lock();
                }
                else {
                    ob.Lock();
                }
            }
        }
        public void Lock()
        {
            lockbtn.Visibility = Visibility.Collapsed;
            unlockbtn.Visibility = Visibility.Visible;
        }
        #endregion   
  
        #region 显示控件集合方法
        private void unhiddenbtn_Click(object sender, RoutedEventArgs e)
        {
            if (uie != null)
            {
                if (theType == "img")
                {
                    Image img = uie as Image;
                    List<string> taglist = img.Tag as List<string>;
                    taglist[1] = "false";
                    img.Tag = taglist;
                    img.Visibility = Visibility.Collapsed;
                    WorkMainAreaUC.layer = AdornerLayer.GetAdornerLayer(WorkMainAreaUC.workcanvas);
                    if (WorkMainAreaUC.myCan != null)
                    {
                        WorkMainAreaUC.layer.Remove(WorkMainAreaUC.myCan);
                    } 
                    unhiddenbtn.Visibility = Visibility.Collapsed;
                    hiddenbtn.Visibility = Visibility.Visible;
                }
                else if (theType == "rect")
                {
                    Rectangle rect = uie as Rectangle;
                    List<string> taglist = rect.Tag as List<string>;
                    taglist[1] = "false";
                    rect.Tag = taglist;
                    rect.Visibility = Visibility.Collapsed;
                    WorkMainAreaUC.layer = AdornerLayer.GetAdornerLayer(WorkMainAreaUC.workcanvas);
                    if (WorkMainAreaUC.myCan != null)
                    {
                        WorkMainAreaUC.layer.Remove(WorkMainAreaUC.myCan);
                    } 
                    unhiddenbtn.Visibility = Visibility.Collapsed;
                    hiddenbtn.Visibility = Visibility.Visible;
                }
                else if (theType == "div")
                {

                    Canvas can = uie as Canvas;
                    Image img = can.Tag as Image;
                    List<string> taglist = img.Tag as List<string>;
                    taglist[1] = "false";
                    img.Tag = taglist;
                    can.Visibility = Visibility.Collapsed;
                    unhiddenDivChild((TreeViewItem)this.Parent);
                    for (int i = 0; i < can.Children.Count; i++)
                    {
                        if (can.Children[i].GetType() == typeof(Image))
                        {
                            Image obc = can.Children[i] as Image;
                            List<string> obctaglist = obc.Tag as List<string>;
                            obctaglist[1] = "false";
                            obc.Tag = obctaglist;
                            obc.Visibility = Visibility.Collapsed;
                        }
                        if (can.Children[i].GetType() == typeof(Rectangle))
                        {
                            Rectangle obc = can.Children[i] as Rectangle;
                            List<string> obctaglist = obc.Tag as List<string>;
                            obctaglist[1] = "false";
                            obc.Tag = obctaglist;
                            obc.Visibility = Visibility.Collapsed;
                        }
                        if (can.Children[i].GetType() == typeof(TextBlock))
                        {
                            TextBlock obc = can.Children[i] as TextBlock;
                            List<string> obctaglist = obc.Tag as List<string>;
                            obctaglist[1] = "false";
                            obc.Tag = obctaglist;
                            obc.Visibility = Visibility.Collapsed;
                        }
                        if (can.Children[i].GetType() == typeof(Canvas))
                        {
                            Canvas obc = can.Children[i] as Canvas;
                            Image obc_img = obc.Tag as Image;
                            List<string> obctaglist = obc_img.Tag as List<string>;
                            obctaglist[1] = "false";
                            obc_img.Tag = obctaglist;
                            obc.Visibility = Visibility.Collapsed;
                        }
                    }
                    WorkMainAreaUC.layer = AdornerLayer.GetAdornerLayer(WorkMainAreaUC.workcanvas);
                    if (WorkMainAreaUC.myCan != null)
                    {
                        WorkMainAreaUC.layer.Remove(WorkMainAreaUC.myCan);
                    }
                    unhiddenbtn.Visibility = Visibility.Collapsed;
                    hiddenbtn.Visibility = Visibility.Visible;
                }
                else if (theType == "page")
                {

                    Canvas can = WorkMainAreaUC.workcanvas;
                    //Image img = can.Tag as Image;
                    //img.Tag = "false";
                    unhiddenDivChild();
                    for (int i = 0; i < can.Children.Count; i++)
                    {
                        if (can.Children[i].GetType() == typeof(Image))
                        {
                            Image obc = can.Children[i] as Image;
                            List<string> obctaglist = obc.Tag as List<string>;
                            obctaglist[1] = "false";
                            obc.Tag = obctaglist;
                            obc.Visibility = Visibility.Collapsed;
                        }
                        if (can.Children[i].GetType() == typeof(Rectangle))
                        {
                            Rectangle obc = can.Children[i] as Rectangle;
                            List<string> obctaglist = obc.Tag as List<string>;
                            obctaglist[1] = "false";
                            obc.Tag = obctaglist;
                            obc.Visibility = Visibility.Collapsed;
                        }
                        if (can.Children[i].GetType() == typeof(TextBlock))
                        {
                            TextBlock obc = can.Children[i] as TextBlock;
                            List<string> obctaglist = obc.Tag as List<string>;
                            obctaglist[1] = "false";
                            obc.Tag = obctaglist;
                            obc.Visibility = Visibility.Collapsed;
                        }
                        if (can.Children[i].GetType() == typeof(Canvas))
                        {
                            Canvas obc = can.Children[i] as Canvas;
                            Image obc_img = obc.Tag as Image;
                            List<string> obctaglist = obc_img.Tag as List<string>;
                            obctaglist[1] = "false";
                            obc_img.Tag = obctaglist;
                            obc.Visibility = Visibility.Collapsed;
                        }
                    }
                    unhiddenbtn.Visibility = Visibility.Collapsed;
                    hiddenbtn.Visibility = Visibility.Visible;
                }
            }
        }
        public void unhiddenDivChild()
        {
            TreeViewItem tv = theTreeView.Items[0] as TreeViewItem;
            for (int i = 0; i < tv.Items.Count; i++)
            {
                TreeViewItem tvi = tv.Items[i] as TreeViewItem;
                ObjectTreeViewUC ob = tvi.Header as ObjectTreeViewUC;
                if (ob.theType == "div")
                {
                    unhiddenDivChild(tvi);
                    ob.UnHidden();
                }
                else
                {
                    ob.UnHidden();
                }
            }
        }
        public void unhiddenDivChild(TreeViewItem tvi)
        {
            for (int i = 0; i < tvi.Items.Count; i++)
            {
                TreeViewItem tv = tvi.Items[i] as TreeViewItem;
                ObjectTreeViewUC ob = tv.Header as ObjectTreeViewUC;
                if (ob.theType == "div")
                {
                    unhiddenDivChild(tv);
                    ob.UnHidden();
                }
                else
                {
                    ob.UnHidden();
                }
            }
        }
        public void UnHidden()
        {
            unhiddenbtn.Visibility = Visibility.Collapsed;
            hiddenbtn.Visibility = Visibility.Visible;
        }
        #endregion

        #region 隐藏控件集合方法
        private void hiddenbtn_Click(object sender, RoutedEventArgs e)
        {
            if (uie != null)
            {
                if (theType == "img")
                {
                    Image img = uie as Image;

                    List<string> taglist = img.Tag as List<string>;
                    taglist[1] = "true";
                    img.Tag = taglist;
                    img.Visibility = Visibility.Visible;
                    hiddenbtn.Visibility = Visibility.Collapsed;
                    unhiddenbtn.Visibility = Visibility.Visible;
                }
                else if (theType == "rect")
                {
                    Rectangle rect = uie as Rectangle;
                    List<string> taglist = rect.Tag as List<string>;
                    taglist[1] = "true";
                    rect.Tag = taglist;
                    rect.Visibility = Visibility.Visible;
                    hiddenbtn.Visibility = Visibility.Collapsed;
                    unhiddenbtn.Visibility = Visibility.Visible;
                }
                else if (theType == "div")
                {
                    Canvas can = uie as Canvas;
                    Image img = can.Tag as Image;
                    List<string> taglist = img.Tag as List<string>;
                    taglist[1] = "true";
                    img.Tag = taglist;
                    can.Visibility = Visibility.Visible;
                    // Image img = can.Tag as Image;
                    // img.Tag = "true";
                    hiddenDivChild((TreeViewItem)this.Parent);
                    for (int i = 0; i < can.Children.Count; i++)
                    {
                        if (can.Children[i].GetType() == typeof(Image))
                        {
                            Image obc = can.Children[i] as Image;
                            List<string> obctaglist = obc.Tag as List<string>;
                            obctaglist[1] = "true";
                            obc.Tag = obctaglist;
                            obc.Visibility = Visibility.Visible;
                        }
                        if (can.Children[i].GetType() == typeof(Rectangle))
                        {
                            Rectangle obc = can.Children[i] as Rectangle;
                            List<string> obctaglist = obc.Tag as List<string>;
                            obctaglist[1] = "true";
                            obc.Tag = obctaglist;
                            obc.Visibility = Visibility.Visible;
                        }
                        if (can.Children[i].GetType() == typeof(TextBlock))
                        {
                            TextBlock obc = can.Children[i] as TextBlock;
                            List<string> obctaglist = obc.Tag as List<string>;
                            obctaglist[1] = "true";
                            obc.Tag = obctaglist;
                            obc.Visibility = Visibility.Visible;
                        }
                        if (can.Children[i].GetType() == typeof(Canvas))
                        {
                            Canvas obc = can.Children[i] as Canvas;
                            Image obc_img = obc.Tag as Image;
                            List<string> obctaglist = obc_img.Tag as List<string>;
                            obctaglist[1] = "true";
                            obc_img.Tag = obctaglist;
                            obc.Visibility = Visibility.Visible;
                        }
                    }

                    hiddenbtn.Visibility = Visibility.Collapsed;
                    unhiddenbtn.Visibility = Visibility.Visible;
                }
                else if (theType == "page")
                {
                    hiddenDivChild();
                    Canvas can = WorkMainAreaUC.workcanvas;

                    for (int i = 0; i < can.Children.Count; i++)
                    {
                        if (can.Children[i].GetType() == typeof(Image))
                        {
                            Image obc = can.Children[i] as Image;
                            List<string> obctaglist = obc.Tag as List<string>;
                            obctaglist[1] = "true";
                            obc.Tag = obctaglist;
                            obc.Visibility = Visibility.Visible;
                        }
                        if (can.Children[i].GetType() == typeof(Rectangle))
                        {
                            Rectangle obc = can.Children[i] as Rectangle;
                            List<string> obctaglist = obc.Tag as List<string>;
                            obctaglist[1] = "true";
                            obc.Tag = obctaglist;
                            obc.Visibility = Visibility.Visible;
                        }
                        if (can.Children[i].GetType() == typeof(TextBlock))
                        {
                            TextBlock obc = can.Children[i] as TextBlock;
                            List<string> obctaglist = obc.Tag as List<string>;
                            obctaglist[1] = "true";
                            obc.Tag = obctaglist;
                            obc.Visibility = Visibility.Visible;
                        }
                        if (can.Children[i].GetType() == typeof(Canvas))
                        {
                            Canvas obc = can.Children[i] as Canvas;
                            Image obc_img = obc.Tag as Image;
                            List<string> obctaglist = obc_img.Tag as List<string>;
                            obctaglist[1] = "true";
                            obc_img.Tag = obctaglist;
                            obc.Visibility = Visibility.Visible;
                        }
                    }
                    hiddenbtn.Visibility = Visibility.Collapsed;
                    unhiddenbtn.Visibility = Visibility.Visible;
                }
            }
        }
        public void hiddenDivChild()
        {

            TreeViewItem tv = theTreeView.Items[0] as TreeViewItem;
            for (int i = 0; i < tv.Items.Count; i++)
            {
                TreeViewItem tvi = tv.Items[i] as TreeViewItem;
                ObjectTreeViewUC ob = tvi.Header as ObjectTreeViewUC;
                if (ob.theType == "div")
                {
                    hiddenDivChild(tvi);
                    ob.Hidden();
                }
                else
                {
                    ob.Hidden();
                }
            }
        }
        public void hiddenDivChild(TreeViewItem tvi)
        {
            for (int i = 0; i < tvi.Items.Count; i++)
            {
                TreeViewItem tv = tvi.Items[i] as TreeViewItem;
                ObjectTreeViewUC ob = tv.Header as ObjectTreeViewUC;
                if (ob.theType == "div")
                {
                    hiddenDivChild(tv);
                    ob.Hidden();
                }
                else
                {
                    ob.Hidden();
                }
            }
        }
        public void Hidden()
        {
            hiddenbtn.Visibility = Visibility.Collapsed;
            unhiddenbtn.Visibility = Visibility.Visible;
        }
        #endregion
    }
}
